﻿using System.Web.Mvc;
using Turquoise.Business.Abstract;
using Turquoise.Helpers;
using Turquoise.Web.Common.Helpers;
using Turquoise.Web.Common.Infrastructure;

namespace Turquoise.Web.Management.Controllers.Partials.Captcha
{
    public class CaptchaController : TurquoiseController
    {
        #region Global Declarations
        private readonly ISettingService _settingService;

        public CaptchaController(ISettingService settingService)
        {
            _settingService = settingService;
        }

        #endregion
        #region Methods
        public FileResult Get()
        {
            var imgPath = Server.MapPath(_settingService.GetValueByKey("CaptchaBackgroundImagePath"));
            var captchaLenght = _settingService.GetValueByKey("CaptchaLenght").ConvertToInt();
            return File(CaptchaHelper.GetCaptchaBytes(imgPath, captchaLenght), "image/jpeg");
        }
        #endregion
    }
}